<!DOCTYPE html>
<html lang="zh-CN">
<head>
    {include file="public/header"}
    <link type="text/css" rel="stylesheet" href="/public/static/dist/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css"/>
    <script src="/public/static/dist/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
    <script src="/public/static/dist/bootstrap-datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="/public/static/dist/wangEditor/wangEditor.min.js"></script>
    <style>
        #edit-table th{
            width:100px;
        }
    </style>
</head>
<body>
<div class="container-fluid">
    <form>
        <table id="edit-table" class="table table-bordered">

            <tr>
                <th>标题</th>
                <td colspan="3"><input name="title" class="title form-control param" must="1" desc="标题" value="{$data.title|default=''}"/></td>
            </tr>
            <tr>
                <th>摘要</th>
                <td colspan="3"><input name="summary" class="summary form-control param" must="1" desc="摘要" value="{$data.summary|default=''}"/></td>
            </tr>
            <tr>
                <th>关键字</th>
                <td colspan="3"><input placeholder="多个用英文逗号隔开" name="key_words" must="1" desc="关键字" class="key_words form-control param" value="{$data.key_words|default=''}"/></td>
            </tr>
            <tr>
                <th>有效日期</th>
                <td colspan="3" class="form-inline">
                    <input name="start_time" class="time form-control param" desc="有效开始日期" must="1" value="{$data.start_time|default=''}"/>
                    至
                    <input name="end_time" placeholder="一直启用为空" class="time form-control param" mast="0" value="{$data.end_time|default=''}"/>
                </td>
            </tr>
            <tr>
                <th>所属栏目</th>
                <td style="width:300px;">
                    <select name="category" class="category form-control param" must="1" desc="所属栏目">
                        {foreach $categoryList as $key=>$vo}
                        <option {if !empty($data) && $data['category_code'] == $vo}selected='selected'{/if} value="{$vo.code}">{$vo.name}</option>
                        {/foreach}
                    </select>
                </td>
                <th>是否置顶</th>
                <td>
                    <input type="radio" name="is_top" class="param" value="1" id="is_top_1"/><label for="is_top_1">是</label>&#12288;
                    <input type="radio" name="is_top" class="param" value="0" id="is_top_2"/><label for="is_top_2">否</label>
                </td>
            </tr>
            <tr>
                <th>排序</th>
                <td><input type="number" name="sort" class="form-control param" must="1" desc="排序" value="{$data.sort|default='1'}"/></td>
                <th>状态</th>
                <td>
                    <input type="radio" checked="checked" class="param" value="1" name="status" id="status_1"/><label for="status_1">启用</label>&#12288;
                    <input type="radio" name="status" class="param" value="0" id="status_2"/><label for="status_2">停用</label>
                </td>
            </tr>
            <tr>
                <th>文章内容</th>
                <td colspan="3" style="height:300px;">

                    <div id="editor">
                        <p>
                            {$data.content|raw|default=''}
                        </p>
                    </div>
                </td>
            </tr>
            <input type="hidden" name="code" value="{$data.code|default=''}" class="param" must="0"/>
        </table>
    </form>
    <button class="btn btn-primary" id="btn-save">保存</button>
    &#12288;
    <button class="btn btn-info">返回</button>
</div>
</body>
</html>
<script>
    //日期选择初始化
    var dataPickerOpt = {
        format: "yyyy-mm-dd",
        autoclose:true,
        language:'zh-CN',
        todayHighlight: true,
        minView:2,
        todayBtn:true,
    };
    $('input[name=start_time]').datetimepicker(dataPickerOpt).on("changeDate", function(e){
        $('input[name=end_time]').datetimepicker("setStartDate",e.date);
    });
    $('input[name=end_time]').datetimepicker(dataPickerOpt).on("changeDate", function(e){
        $('input[name=start_time]').datetimepicker("setEndDate",e.date);
    });

    //富文本编辑器初始化
    var E = window.wangEditor
    var editor = new E('#editor')
    // 或者 var editor = new E( document.getElementById('editor') )
    editor.customConfig.uploadImgServer = '/public/admin/Post/upload'  // 上传图片到服务器
    editor.create();


    //保存方法
    $("#btn-save").click(function(){
        var param = getParam();
        if(param == -1){
            return;
        }
        var content = editor.txt.html();
        if(content == ''){
            alertMsg({"msg":'请输入文章内容', "type":0});
            return;
        }
        param.content = content;
        $.ajax({
            url:'/public/admin/post/ajax_save',
            data:param,
            dataType:'json',
            type:'post',
            success:function(data){
                if(data.code !=1){
                    alertMsg({"msg":data.msg, "type":0});
                }else{
                    alertMsg({"msg":data.msg, "type":1});
                }
            }
        });
    });
</script>